<template>
  <div class="components-container">
    <!-- 查询条件 -->
    <div class="header-form">
       <div class="layui-inline">
        <label class="layui-form-label">冰柜编号</label>
         <div class="layui-input-inline">
            <el-input  v-model="selectData.IceNoLike" placeholder="请输入冰柜编号" ></el-input>
         </div>
      </div>
      <div class="layui-inline">
        <label class="layui-form-label">所属区域</label>
      
          <div class="layui-input-inline">
              <el-select v-model="selectData.IcaNameLike" placeholder="请选择冰柜所属区域"  style="width:100%">
                 <el-option label="全部" :value="null"></el-option>
                <el-option v-for="item in iceAreas" :key="item.value" :label="item.label" :value="item.value"></el-option>
              </el-select>
          </div>
      </div>
     <div class="layui-inline">
        <label class="layui-form-label">类别</label>
       
       <div class="layui-input-inline">
              <el-select v-model="selectData.IceCodNameLike" placeholder="请选择类别"  style="width:100%">
                <el-option label="全部" :value="null"></el-option>
                <el-option v-for="item in iceTypes" :key="item.value" :label="item.label" :value="item.value"></el-option>
              </el-select>
            </div>
      </div>
      <el-button type="primary"  @click="btnSearch" >搜索</el-button>
      <el-button  @click="btnRepeat">重置</el-button>
    </div>
    <!-- 功能列表 -->
    <div>
      <ul class="toolList">
        <li v-if="btnShow(item.BTNVALUE)" v-for="(item, index) in $store.state.btnListCommon" @click="operate(item.BTNVALUE)">
          <el-button type="primary" :value="item.BTNSHOWNAME" v-text="item.BTNSHOWNAME"></el-button>
        </li>
      </ul>
    </div>
    <!--数据列表-->
    <dataTable :headList="headList" :dataList="dataList" :pageOrder="pageOrder" @pageChange="pageChange" @selectRow="selectRow"></dataTable>

    <freezerManageMain ref="sweetModalMain" :orderType="order" @refreshData="getData"></freezerManageMain>

    <staEndUse ref="useMain" @refreshData="getData"></staEndUse>
  </div>
</template>
<style rel="stylesheet/scss" lang="scss" scoped>
@import "src/styles/common.scss";
.btnCenter {
  text-align: center;
}
</style>
<script>
import freezerManageMain from "./freezerManageMain";
import staEndUse from "./staEndUse";
import dataTable from "@/components/Table/DataTable";
import apiBase from "@/api/apiBase.js";
import { manage } from "@/mixins/managePage.js";
import { ORDER } from "@/const/orderConst.js";

// const ADD = "新增";
// const MODIFY = "修改";
// const DELETE = "删除";
// const INFO = "详情";
export default {
  name: "freezerManage",
  mixins: [manage],
  data() {
    return {
      loading: false,
      iceAreas: [],
      iceTypes: [],
      selectData: {},
      Data: {}
    };
  },
  methods: {
    //功能操作
    operate(order) {
      console.log(order)
      this.order = order;
      this.dataRepeat();
      switch (this.order) {
        case ORDER.ADD:
          this.$refs.sweetModalMain.open(this.order);
          break;
        case ORDER.MODIFY:
        case ORDER.INFO:
          this.$refs.sweetModalMain.open(this.order, this.currentRow.ICEID);
          break;
        case ORDER.DELETE:
          this.$refs.sweetModalMain.open(this.order, this.currentRow.ICEID);
          break;
        case ORDER.START:
        case ORDER.END:
          this.$refs.useMain.open(this.order, this.currentRow.ICEID);
          break;
        default:
      }
    },
    //获取列项
    getColumns() {
      apiBase.DoService(
        {},
        apiBase.getApiAdress().Column.GetIceColumns,
        res => {
          this.headList = res.data.content;
        }
      );
    },
    //获取数据
    getData() {
      let Data = JSON.parse(JSON.stringify(this.selectData));
      var data = {
        PageIndex: this.pageOrder.currentPage,
        PageSize: this.pageOrder.pageSize,
        OrderBy: this.pageOrder.orderType,
        OrderByType: this.pageOrder.orderSort,
        Data: Data
      };
      apiBase.DoService(data, apiBase.getApiAdress().Ice.Query, res => {
        this.dataList = res.data.content.OutData;
        this.pageOrder.totalNum = res.data.content.RecordCount;
      });
    },
    //获取所属区域
    getIceAreas() {
      apiBase.DoService({}, apiBase.getApiAdress().Ice.QueryIceArea, res => {
        let icaNameData = res.data.content,
          legendsIcaData = icaNameData.map(item => ({
            label: item.ICANAME,
            value: item.ICAID
          }));
        this.iceAreas = legendsIcaData;
      });
    },
    //获取冰柜类别
    getIceTypes() {
      apiBase.DoService({}, apiBase.getApiAdress().Code.GetIceType, res => {
        let iceTypeData = res.data.content,
          legendsIceData = iceTypeData.map(item => ({
            label: item.CodeName,
            value: item.CodeValue
          }));
        this.iceTypes = legendsIceData;
      });
    },
    //查询条件重置
    btnRepeat() {
      this.selectData = {};
      this.getData();
    },
    btnShow(btn) {
      let status = '';
      if (this.currentRow) {
        status = this.currentRow.ICESTATUS;
      }
      switch (btn) {
        case ORDER.ADD:
          return true;
          break;
        case ORDER.INFO:
        case ORDER.MODIFY:
        case ORDER.DELETE:
          return status !== '';
          break;
        case ORDER.END:
          return status === 'A';
          break;
        case ORDER.START:
          return status === 'B';
        default:
      }
    },
    //数据重置
    dataRepeat() {
      this.Data = {};
    }
  },
  mounted() {},
  components: {
    freezerManageMain,
    staEndUse,
    dataTable
  },
  created() {
    this.getColumns();
    this.getData();
    this.getIceTypes();
    this.getIceAreas();
  }
};
</script>